package com.zb.service.impl;
import com.zb.mapper.ShipmentsMapper;
import com.zb.entity.Shipments;
import org.springframework.stereotype.Service;
import com.zb.service.ShipmentsService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.zb.util.PageUtil;
import java.util.ArrayList;
import java.util.HashMap;

@Service
public class ShipmentsServiceImpl implements ShipmentsService {

    @Autowired
    private ShipmentsMapper shipmentsMapper;

    public Shipments getShipmentsById(Long id)throws Exception{
        return shipmentsMapper.getShipmentsById(id);
    }

    public List<Shipments>	getShipmentsListByMap(Map<String,Object> param)throws Exception{
        return shipmentsMapper.getShipmentsListByMap(param);
    }

    public Integer getShipmentsCountByMap(Map<String,Object> param)throws Exception{
        return shipmentsMapper.getShipmentsCountByMap(param);
    }

    public Integer qdtxAddShipments(Shipments shipments)throws Exception{
            //shipments.setCreatedTime(new Date());
            return shipmentsMapper.insertShipments(shipments);
    }

    public Integer qdtxModifyShipments(Shipments shipments)throws Exception{
        //shipments.setUpdatedTime(new Date());
        return shipmentsMapper.updateShipments(shipments);
    }

    public Integer qdtxDeleteShipmentsById(Long id)throws Exception{
        return shipmentsMapper.deleteShipmentsById(id);
    }

    public PageUtil<Shipments> queryShipmentsPageByMap(Map<String,Object> param,Integer index,Integer size)throws Exception{
        param.put("start",(index-1)*size);
        param.put("size", size);

        List<Shipments> shipmentsList = shipmentsMapper.getShipmentsListByMap(param);
        Integer count = shipmentsMapper.getShipmentsCountByMap(param);

        PageUtil<Shipments> page = new PageUtil<Shipments>();
        page.setData(shipmentsList);
        page.setIndex(index);
        page.setSize(size);
        page.setCount(count);
        return page;
    }

    public Integer qdtxBatchDeleteShipments(String ids)throws Exception{
        Map<String,List<String>> param=new HashMap<String,List<String>>();
        String[] paramArrays=ids.split(",");
        List<String> idList=new ArrayList<String>();
            for (String temp:paramArrays){
                idList.add(temp);
            }
        param.put("ids",idList);
        return shipmentsMapper.batchDeleteShipments(param);
    }


}
